package two;

public class A030 {


    //24.两两交换链表的节点

    public ListNode swapPairs(ListNode head) {
        if(head==null || head.next==null) return head;
        ListNode left = head;
        ListNode right = head.next;
        ListNode newHead = new ListNode();
        ListNode cur = newHead;
        while(left!=null && right!=null) {
            cur.next = right;
            left.next = right.next;
            right.next=left;
            cur = left;
            left=left.next;
            if(left!=null) right=left.next;
        }
        return newHead.next;
    }
}
